package com.neulogistics.contrib.procuredcenter.infrastructure.persistence.repository;

import com.neulogistics.contrib.procuredcenter.domain.model.aggregate.GoodsSet;
import com.neulogistics.contrib.procuredcenter.domain.repository.IGoodsSetRepository;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.converter.GoodsSetEntityPOConverter;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.po.GoodsSetPO;
import com.neulogistics.contrib.procuredcenter.infrastructure.persistence.orm.service.IGoodsSetPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class GoodsSetRepository implements IGoodsSetRepository {
    @Resource
    IGoodsSetPOService goodsSetPOService;

    @Override
    public void save(GoodsSet goodsSet) {
        GoodsSetPO goodsSetPO = GoodsSetEntityPOConverter.entityToPO(goodsSet);
        goodsSetPOService.saveOrUpdate(goodsSetPO);
        goodsSet.setSetId(goodsSetPO.getSetId());
    }

    @Override
    public GoodsSet findById(Integer id) {
        GoodsSetPO goodsSetPO = goodsSetPOService.getById(id);
        GoodsSet goodsSet = GoodsSetEntityPOConverter.POToEntity(goodsSetPO);
        return goodsSet;
    }

    @Override
    public void deleteById(Integer id) {
        goodsSetPOService.removeById(id);
    }
}
